<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="utf-8">
		<title> &nbsp;</title>
		<script src='${ctxPath}/assets/mui/js/jquery-1.11.3.js'></script>
	</head>
	<style>
		p{
			font-size: 12px;
			margin: 0;
		}
		.button{
			background-color: #A6A6A6; color: black; /* Green */
		    border: none;
		    color: white;
		    padding: 10px 32px;
		    text-align: center;
		    text-decoration: none;
		    display: inline-block;
		    font-size: 14px;
    	}
	</style>
	<body>
		<div style="width: 100%;">
			<button id="button" class="button" onclick="doPrint()">打印</button>
		</div>
		<div id="big" style="width: 100%;">
		</div>
		<script type="text/jscript">
			//通过URL 获取参数
			function GetQueryString(name) {
				var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
				var r = window.location.search.substr(1).match(reg);
				if(r != null) return unescape(r[2]);
				return null;
			};
			var ids = GetQueryString("ids");
			var arrids = [];
			arrids = ids.split(",");
			var now = new Date()
			var year = now.getFullYear()
			var month = now.getMonth()+1
			var day = now.getDate()
			var hour = now.getHours()
			var m = now.getMinutes()
			var s = now.getSeconds()
			var newdate = year+"-"+month+"-"+day+" "+hour+":"+m+":"+s
			function findtou(aa,setUnit,getWarehouse){
				return '<div id="-title" style="width: 100%; height: 25px;margin-top: 10px;">'+
					'<p style="float: left; width: 55%;height: 2px;text-align: right;font-size: 18px;font-weight: 600;">入库订单</p>'+
					'<p style="float: right; width: 45%;height: 2px;text-align: right;">'+aa+'  打印时间：'+newdate+'</p>'+
				'</div>'+
				'<div id="-title-l" style="width: 100%; height: 20px;">'+
					'<p style="float: left; width: 50%;height: 2px;">发货客户：'+setUnit+'</p>'+
					'<p style="float: left; width: 50%;height: 2px;text-align: center;">收货仓库：'+getWarehouse+'</p>'+
				'</div>';
			}
			load();
			function load(){
				var big = $("#big");
				//big.append(storageOutmsg);
				for(var i = 0; i <arrids.length; i++){
					$.ajax({
					    url:'${ctxPath}/hxOrderPut/getPrintOrderPut',
					    type:'post',
					    dataType:'json',
					    data:{"id":arrids[i]},
					    success:function(data){
					        if(data!=null){
						 		var storageOuttitle = '<div id="order-title" style="width: 100%;height: 30px;margin-top: 10px;">'+
															'<div id="order-title-1" style="width: 100%;">'+
																'<p style="float: left; width: 25%;">订单号：'+data.orderPutNumber+'</p>'+
																'<p style="float: left; width: 25%;">单据类型：'+data.orderType+'</p>'+
																'<p style="float: left; width: 25%;">预约时间：'+data.yuyueTime+'</p>'+
																'<p style="float: left; width: 25%;">留言备注：'+data.notes+'</p>'+
															'</div>'+
														'</div>';

						 		var storageOutbottom = '<div id="order-title" style="width: 100%;height: 30px;">'+
						 								'<div id="order-title-1" style="width: 100%;">'+
																'<p style="font-size: 20px;float: left; width: 25%;">实收：____________'+
															'</div>'+
														'</div>'+
														'<br/>' +

						 								'<div id="order-title" style="width: 100%;height: 30px;">'+
						 								'<div id="order-title-1" style="width: 100%;">'+
																'<p style="font-size: 20px;float: left; width: 25%;">拒收：____________'+
															'</div>'+
														'</div>'+
														'<br/>' +

						 								'<div id="order-title" style="width: 100%;height: 30px;" >'+
						 								'<div id="order-title-1" style="width: 100%;">'+
																'<p style="font-size: 20px;float: left; width: 25%;">破损：____________'+
															'</div>'+
														'</div>' +
														'<br/>' +

														'<br/>' +
						 								'<div id="order-title" style="width: 100%;height: 30px; ">'+
															'<div id="order-title-1" style="width: 100%;">'+
																'<p style="float: left; width: 25%;">打印人：'+data.printName+'</p>'+
																'<p style="float: left; width: 25%;">制单人：'+data.createUserName+'</p>'+
																'<p style="float: right; width: 25%;">收货专员：</p>'+
																'<p style="float: right; width: 25%;">装卸员：</p>'+
															'</div>'+
														'</div>'+
														'<div id="order-title" style="width: 100%;height: 30px;">'+
														'<div id="order-title-1" style="width: 100%;">'+
															'<p style="float: left; width: 25%;">驾驶员：</p>'+
															'<p style="float: left; width: 25%;">车牌号：</p>'+
															'<p style="float: right; width: 25%;">司机电话：</p>'+
															'<p style="float: right; width: 25%;">日期：</p>'+
														'</div>'+
													'</div>';
								$.ajax({
									url:'${ctxPath}/hxOrderPut/getPrintOrderPutDetailed',
									type:'post',
									dataType:'json',
                					async:false,
									data:{"orderPutNumber":data.orderPutNumber},
									success:function(data1){
										if(data1.length>0){
											$.each(data1,function(key,value){
												var ncont = 0.0;
												var vcont = 0.0;
												var wcont = 0.0;
												var storageOutdata = '<div id="order-date" style="width: 100%;height: 700px;">'+
																'<table id="order-table" style="width: 100%; font-size: 12px;" border="1px solid" cellpadding="0" cellspacing="0">'+
																	'<thead>'+
																		'<th>商品编号</th>'+
																		'<th>商品码</th>'+
																		'<th>商品名称</th>'+
																		'<th>规格</th>'+
																		'<th>单位</th>'+
																		'<th>数量</th>'+
																		'<th>赠品单位</th>'+
																		'<th>赠品数量</th>'+


																		'<th>总数量</th>'+
																		'<th>码托规则</th>'+
																	'</thead>'+

																	'<tbody>';
												$.each(value.list,function(key1,value1){
													ncont += value1.sumNum*1;
													vcont += value1.putVolume*1;
													wcont += value1.putWeight*1;

													storageOutdata += '<tr>'+
																			'<td>'+value1.goodsNumber+'</td>'+
																			'<td>'+value1.goodsPcode69+'</td>'+
																			'<td>'+value1.goodsName+'</td>'+
																			'<td>'+value1.goodsSpecs+'</td>'+
																			'<td>'+value1.unit+'</td>'+
																			'<td>'+value1.num+'</td>'+
																			'<td>'+value1.zpUnit+'</td>'+
																			'<td>'+value1.zpNum+'</td>'+
																			'<td>'+value1.sumNum+'</td>'+
																			'<td>'  + '底：' + value1.goodsBottom  + '&nbsp;&nbsp;&nbsp;层：' + value1.goodsLamination + '</td>' +
																		'</tr>';
												});
												storageOutdata += '<tr >'+
																		'<td></td>'+
																		'<td></td>'+
																		'<td></td>'+
																		'<td></td>'+
																		'<td></td>'+
																		'<td></td>'+
																		'<td>小计：</td>'+
																		'<td></td>'+
																		'<td>'+Math.round(ncont * 100) / 100+'</td>'+
																		'<td></td>'+
																	'</tr>';
												storageOutdata += '</tbody>'; // 结束表格体
												storageOutdata += '</table>'; // 结束表格

												// 注意：这里的合计信息被移出了表格，并添加了一个新的div来包裹它
												storageOutdata += '<div id="order-summary" style="width: 100%; margin-top: 10px;">';
												storageOutdata += '<p style="font-size: 15px;float: right; width: 25%;  padding-right: 15px; ">合计：' + data.putNum + '</p>'
												storageOutdata += '</div>'; // 结束合计信息的div

												storageOutdata += '</div>'; // 结束包裹整个表格和合计信息的外部div

												var tou = findtou('第'+(key+1)+'页  '+'共'+data1.length+'页',data.setUnit,data.getWarehouse)
												big.append(tou+storageOuttitle+storageOutdata+storageOutbottom);
											});
										}else{
								 			alert("未查询到入库单明细!");
										}
									},
									error:function(data){
										alert("查询入库单明细异常!");
									}
								});
					 		}else{
					 			alert("未查询到入库单!");
					 		}
					    },
					    error: function(data){
							alert("查询入库单异常!");
					    }
					});
				}
			};
			//打印
			function doPrint() {
		        bdhtml = window.document.body.innerHTML;
		        phtnl = window.document.getElementById("big").innerHTML;
		        window.document.body.innerHTML = phtnl; //把需要打印的指定内容赋给big
		        window.print(); //调用浏览器的打印功能打印指定区域
		        window.document.body.innerHTML=bdhtml; // 最后还原页面
		    };
		    //打印的回调
		    var beforePrint = function() {
		        //打印前调用
		    };
		    var afterPrint = function() {
		        //打印后调用
            	var Indexs = parent.layer.getFrameIndex(window.name);
                parent.layer.close(Indexs);
		    };
		    if (window.matchMedia) {
		        var mediaQueryList = window.matchMedia('print');
		        mediaQueryList.addListener(function(mql) {
		            if (mql.matches) {
		                beforePrint();
		            } else {
		                afterPrint();
		            }
		        });
		    }
		</script>
	</body>
</html>